package com.ropeok.dao.impl;

import com.ropeok.dao.PermissionDao;
import com.ropeok.dao.role_permissionDao;
import com.ropeok.entity.Role;
import com.ropeok.entity.permissions;
import com.ropeok.util.c3p0Util;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class role_permissionDaoImpl implements role_permissionDao {
    Connection connection= c3p0Util.getConnection();
    @Override
    public void SaveRp(Role role, permissions per) {
        try{
            PreparedStatement preparedStatement=connection.prepareStatement("insert into t_user values (?,?)");
            preparedStatement.setInt(1,role.getRoleid());
            preparedStatement.setInt(2,per.getPerid());
            preparedStatement.executeUpdate();
        }catch (SQLException e){
            e.printStackTrace();
        }
    }

    @Override
    public void DelRpRole(Integer id) {
        try {
            PreparedStatement pstm1=connection.prepareStatement("delete from role_permission where role_id=?");
            pstm1.setInt(1,id);
            pstm1.executeUpdate();
        }catch (SQLException e){
            e.printStackTrace();
        }
    }
    @Override
    public void DelRpPermisssion(Integer id){
        try {
            PreparedStatement pstm1=connection.prepareStatement("delete from role_permission where permisssion_id=?");
            pstm1.setInt(1,id);
            pstm1.executeUpdate();
        }catch (SQLException e){
            e.printStackTrace();
        }
    }
}
